package com.example.i.spy;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.view.Menu;
import android.view.MotionEvent;

public class SplashScreen extends Activity 
{

	protected boolean active = true;
	protected int splashTime = 3000;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash_screen);
		this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

		// thread for displaying the SplashScreen
		Thread splashTread = new Thread() 
		{
			// override the thread's run method continue until the user touches the screen or when
			// a certain amount of time has passed. 
			@Override
			public void run() 
			{
				try 
				{
					int waited = 0;
					while(active && (waited < splashTime)) 
					{
						sleep(100);
						if(active)
						{
							waited += 100;
						}
					}
				}
				// If something goes wrong, we do nothing....
				catch(InterruptedException e) 
				{
					// do nothing
				}
				// This is called when the run gets out of the while loop.
				finally 
				{
					finish();
					Intent intent = new Intent(SplashScreen.this, MainMenuActivity.class);
					startActivity(intent);
				}
			}
		};
		splashTread.start();
	}

	// if the user touches the screen, then start the next activity right away
	@Override
	public boolean onTouchEvent(MotionEvent event)
	{
		if (event.getAction() == MotionEvent.ACTION_DOWN)
		{
			active = false;
		}
		return true;
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) 
	{
		getMenuInflater().inflate(R.menu.activity_splash_screen, menu);
		return true;
	}
}
